#include "module.h"
#include "stdio.h"
#include "string.h"
#include "../tools/str.h"
#include "../global.h"
#include "../debug/debug.h"

/**
 * @brief 
 * @param type 
 * @param filebuff 
 * @param fileLen 
 * @param result 
 * @param resultLen 
 * @return size_t 
 */
size_t StaticModule(char *type,char *filebuff,size_t fileLen,char *result,size_t resultLen){
    size_t resultStrLen,dataLength;
    if (StrCmp("image/jpg",type) == EQUAL || StrCmp("image/png",type) == EQUAL)
    {
        sprintf(result,"HTTP/1.1 200 OK\r\nContent-Type:%s\r\ncontent-length: %ld\r\n\r\n",type,fileLen);
    }else{
        sprintf(result,"HTTP/1.1 200 OK\r\nContent-Type:%s\r\n\r\n",type);
    }  
    resultStrLen = strlen(result);
    if (fileLen > (resultLen-resultStrLen))
    {
        WEB_DEBUG(DEBUG_ERROR,"the file length is too long\n");
    }else{
        WEB_DEBUG(DEBUG_INFO,"responseLen:%ld fileLen:%ld\n",resultStrLen,fileLen);
        memcpy(result+resultStrLen,filebuff,fileLen);
    }
    dataLength = resultStrLen+fileLen;

    return dataLength;

}